home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / glue / gen_glue.c next >
C/C++ Source or Header  |  1996-03-13  |  2KB  |  108 lines

  1. #include <sys/types.h>
  2. #include <sys/syscall.h>
  3.  
  4. #include <stdio.h>
  5.  
  6. struct syscall {
  7.   char *name;
  8.   int   vec;
  9. } syscalls[] = {
  10. #define SYSTEM_CALL(func,vec) { #func, vec},
  11. #include <sys/syscall.def>
  12. #undef SYSTEM_CALL
  13. };
  14.  
  15. int nsyscall = sizeof(syscalls) / sizeof (syscalls[0]);
  16.  
  17. #define BASEREL             \
  18. ".globl _%s;                \
  19. _%s: movel a4@(_ixemulbase:W), a0;    \
  20. jmp a0@(%d:w)\n"
  21.  
  22. #define BASEREL_IX_GETA4        \
  23. ".globl _%s;                \
  24. _%s: movel _ixemulbase, a0;        \
  25. jmp a0@(%d:w)\n"
  26.  
  27. #define NOBASEREL            \
  28. ".globl _%s;                \
  29. _%s: movel _ixemulbase, a0;        \
  30. jmp a0@(%d:w)\n"
  31.  
  32. #define PROFILING            \
  33. ".globl _%s;                \
  34. _%s:                    \
  35. .data;                    \
  36. PROF%s:;                \
  37. .long 0;                \
  38. .text;                    \
  39. link a5,#0;                \
  40. lea PROF%s,a0;                \
  41. jsr mcount;                \
  42. unlk a5;                \
  43. movel _ixemulbase, a0;            \
  44. jmp a0@(%d:w)\n"
  45.  
  46. void usage(void)
  47. {
  48.   fprintf(stderr, "Usage: gen_glue baserel | no-baserel | profiling\n");
  49.   exit(1);
  50. }
  51.  
  52. int main(int argc, char **argv)
  53. {
  54.   FILE *fp;
  55.   struct syscall *sc;
  56.   int i, v, baserel = 0, profiling = 0;
  57.  
  58.   if (argc != 2)
  59.     usage();
  60.   if (!strcmp(argv[1], "baserel"))
  61.     {
  62.       baserel = 1; profiling = 0;
  63.     }
  64.   else if (!strcmp(argv[1], "no-baserel"))
  65.     {
  66.       baserel = 0; profiling = 0;
  67.     }
  68.   else if (!strcmp(argv[1], "profiling"))
  69.     {
  70.       baserel = 0; profiling = 1;
  71.     }
  72.   else usage();
  73.   
  74.   for (i = 0, sc = syscalls; i < nsyscall; i++, sc++)
  75.     {
  76.       char name[strlen (sc->name) + 3];
  77.  
  78.       if (!memcmp(sc->name, "__obsolete", 10))
  79.         continue;
  80.       if (!memcmp(sc->name, "__must_recompile", 16))
  81.         continue;
  82.       if (!memcmp(sc->name, "__stk", 5))
  83.         continue;
  84.       v = -(sc->vec + 4)*6;
  85.       sprintf (name, "%s.s", sc->name);
  86.  
  87.       fp = fopen (name, "w");
  88.       
  89.       if (!fp)
  90.         {
  91.           perror (sc->name);
  92.           exit (20);
  93.         }
  94.  
  95.       if (baserel)
  96.         if (sc->vec == SYS_ix_geta4)
  97.           fprintf (fp, BASEREL_IX_GETA4, sc->name, sc->name, v);
  98.     else
  99.           fprintf (fp, BASEREL, sc->name, sc->name, v);
  100.       else if (profiling)
  101.         fprintf (fp, PROFILING, sc->name, sc->name, sc->name, sc->name, v);
  102.       else
  103.         fprintf (fp, NOBASEREL, sc->name, sc->name, v);
  104.       fclose (fp);
  105.     }
  106.   return (0);
  107. }
  108.